<meta charset="UTF-8">
<input type="button" value="上一张" onclick="shang()" />
<input type="button" value="下一张" onclick="xia()"/>
<img src="img/1.jpg" id="d1" width="300px"/>
<script>
	var imgindex=d1.src.indexOf("img/");
	var num=parseInt(imgindex)+4;
	var jpgindex=d1.src.indexOf(".jpg");
	var imgnum=d1.src.substring(num,jpgindex)
	var shang=function(){
		imgnum=parseInt(imgnum)-1;
		if(imgnum>0){
			d1.src="img/"+imgnum+".jpg";
		}else{
			alert("这已经是第一张了")
		}
		
	}
	
	var xia=function(){
		imgnum=parseInt(imgnum)+1;
		if(imgnum<=5){
			d1.src="img/"+imgnum+".jpg";
			
		}else{
			alert("这已经是最后一张了")
		}
	}
</script>

